﻿@{
	Layout = "~/Views/Shared/_Layout.cshtml";
	ViewData["Title"] = "湖北省检察院档案管理系统 - 机构管理";
}


@section Head{
	<link rel="stylesheet" href="~/layuiadmin/layui/font/dtreefont.css" />
	<link rel="stylesheet" href="~/layuiadmin/style/Category/dtree.css" />
}

<div class="layui-row role-body">
	<div class="layui-col-md2 role-left">
		<div id="sxdh" class="layui-box"></div>
	</div>
	<div class="layui-col-md10">
		<div class="layui-fluid">
			<div class="layui-card layui-card-border">
				<div class="layui-card-body">

					<table id="LAY-user-role" lay-filter="LAY-user-role"></table>
				</div>
			</div>
		</div>
	</div>
	<div style="display:none;" id="KindsType">@(ViewData["KindsType"])</div>
</div>

@section scripts{

	<script type="text/html" id="toolbardom">
		<div class="layui-btn-container">
			<button type="button" class="layui-btn layui-btn-sm" lay-event="add">添加</button>
		</div>
	</script>
	<script type="text/html" id="buttonTpl">
		{{#  if(d.bmzt=="1"){ }}
		<input type="checkbox" name="qx" lay-skin="switch" lay-text="可用|停用" checked disabled>
		{{#  } else { }}
		<input type="checkbox" name="qx" lay-skin="switch" lay-text="可用|停用" disabled>
		{{#  } }}
	</script>
	<script type="text/html" id="buttonTp2">

		{{#  if(d.rjb=="1"){ }}
		个人
		{{#  } else if(d.rjb=="2") { }}
		全院
		{{#  }else if(d.rjb=="3") { }}
		部门
		{{#  } }}
	</script>
	<script type="text/html" id="buttonTp3">
		{{#  if(d.qid=="1"){ }}
		<input type="checkbox" name="qx" lay-skin="switch" lay-text="可查阅|不可查阅" checked disabled>
		{{#  } else { }}
		<input type="checkbox" name="qx" lay-skin="switch" lay-text="可查阅|不可查阅" disabled>
		{{#  } }}
	</script>
	<script type="text/html" id="buttonTp4">
		{{#  if(d.yhzt=="1"){ }}
		<input type="checkbox" name="qx" lay-skin="switch" lay-text="在职|离岗" checked disabled>
		{{#  } else { }}
		<input type="checkbox" name="qx" lay-skin="switch" lay-text="在职|离岗" disabled>
		{{#  } }}
	</script>
	<script type="text/html" id="toolexct">
		<div class="layui-btn-group">
			<button type="button" class="layui-btn layui-btn-sm" lay-event='edit'>
				<i class="layui-icon">&#xe642;</i>
			</button>
			<button type="button" class="layui-btn layui-btn-sm" lay-event='delete'>
				<i class="layui-icon">&#xe640;</i>
			</button>
		</div>
	</script>
	<script>
		layui.config({
			base: '/layuiadmin/' //静态资源所在路径
		}).extend({
			index: 'lib/index' //主入口模块
		}).use(['index', 'useradmin', 'table', 'dtree', 'jquery', 'layer', 'form'], function () {
			var form = layui.form
				, table = layui.table, dtree = layui.dtree, $ = layui.$, layer = layui.layer;

			var DWID;
			var KindsType = $("#KindsType").text();
			var tjxx = KindsType == "Dept" ? "添加部门信息" : KindsType == "Role" ? "添加角色信息" : KindsType == "User" ? "添加用户信息" : "";
			table.on('toolbar(LAY-user-role)', function (obj) {
				var checkStatus = table.checkStatus(obj.config.id)
				if (obj.event == 'add') {
					// 弹窗
					var layer1 = layer.open({
						type: 2,
						content: "/Unit/Role/RoleFrom?type=add&DWID=" + DWID + "&KindsType=" + KindsType,
						title: tjxx,
						skin: 'demo-class',
						maxmin: true,
						area: ['500px', '400px'],
						btn: ['确定', '取消']
						, yes: function (index, layero) {
							//点击确认触发 iframe 内容中的按钮提交
							var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
							submit.click();
						}
						, end: function (index) {
							table.reload('LAY-user-role'); //重载表格
							layer.close(index); //再执行关闭
						},
						zIndex: layer.zIndex, //重点1
						success: function (layero) {
							layer.setTop(layero); //重点2
						}
					})
				}
			})

			table.on('tool(LAY-user-role)', function (obj) {
				var data = obj.data; //获得当前行数据
				var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
				var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）

				var tryhid = KindsType == "Dept" ? tr.find("td[data-field=bmid]").text() : KindsType == "Role" ? tr.find("td[data-field=rid]").text() : KindsType == "User" ? tr.find("td[data-field=yhid]").text() : "";;
				if (layEvent == 'edit') {
					top.layer.open({
						type: 2,
						title: "编辑账号",
						content: "/Unit/Role/RoleFrom?type=edit&yhid=" + tryhid + "&DWID=" + DWID + "&KindsType=" + KindsType,
						maxmin: !0,
						area: ["500px", "400px"],
						btn: ["确定", "取消"],
						yes: function (e, i) {
							var submit = i.find('iframe').contents().find("#layuiadmin-app-form-edit");
							submit.click();
						},
						end: function (index) {
							table.reload('LAY-user-role'); //重载表格
							layer.close(index); //再执行关闭
						}
					})
				} else if (layEvent = 'delete') {
					var layerindex = layer.prompt({
						formType: 1
						, title: '敏感操作，请验证口令'
					}, function (value, index) {
						layer.confirm('确定删除吗？', function (index) {
							$.post({
								url: "/Unit/Role/del?yhid=" + tryhid + "&KindsType=" + KindsType
								, success: function () {
									layer.close(layerindex);
									table.reload('LAY-user-role');
									layer.msg('已删除');
								}
							});
						});
					});
				}
			})
			// table.on('row(LAY-user-role)', function(obj) {
			// 	obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
			// 	obj.tr.find('i[class="layui-anim layui-icon"]').trigger("click");
			// });


			// 树导航

			$.get("/Unit/Role/GetAllDtreeJson", function (data, status) {
				for (var i = 0; i < data.count; i++) {
					DTree1 = dtree.render({
						elem: "#sxdh",
						data: [{
							"id": data.data[i]["dwid"],
							"title": data.data[i]["dwmc"],
						}],
						initLevel: "2",
						ficon: ["1", "-1"],
						leafIconArray: { "11": "dtree-icon-star" },
						done: function () {
							var params = dtree.click(DTree1, '1')
						}
					});
				}
			})
			var Dept = [{ type: 'radio', fixed: 'left' },
			{ field: 'bmid', title: 'ID', hide: true },
			{ field: "bmmc", title: '名称' },
			{ field: "bmdm", title: '代码' },
			{ field: "bmpy", title: '拼音码' },
			{ field: "bmbz", title: '备注' },
			{ field: "bmbh", title: '编号' },
			{ field: "bmzt", title: '部门状态', templet: '#buttonTpl', align: 'center' },
			{ title: '操作', templet: '#toolexct', align: 'center' }]
			var Role = [{ type: 'radio', fixed: 'left' },
			{ field: 'rid', title: 'ID', hide: true },
			{ field: "rmc", title: '角色名称' },
			{ field: "rdm", title: '角色代码' },
			{ field: "rjb", title: '阅卷权限', templet: '#buttonTp2' },
			{ field: "rbz", title: '备注' },
			{ title: '操作', templet: '#toolexct', align: 'center' }]
			var User = [{ type: 'radio', fixed: 'left' },
			{ field: 'yhid', title: 'ID', hide: true },
			{ field: "yhzh", title: '用户账号' },
			{ field: "yhmc", title: '姓名' },
			{ field: "rmc", title: '身份' },
			{ field: "bmmc", title: '部门' },
			{ field: "yhdh", title: '用户电话' },
			{ title: '权限范围', field: "qid", templet: '#buttonTp3', align: 'center' },
			{ title: '状态', field: "yhzt", templet: '#buttonTp4', align: 'center' },
			{ field: "yhbz", title: '备注' },
			{ title: '操作', templet: '#toolexct', align: 'center' }]
			var tabletype = KindsType == "Dept" ? Dept : KindsType == "Role" ? Role : KindsType == "User" ? User : "";
			dtree.on("node('sxdh')", function (obj) {
				DWID = obj.param['nodeId'];
				table1 = table.render({
					elem: '#LAY-user-role',
					url: "/Unit/Role/GetAllDateJson?dwid=" + DWID + "&KindsType=" + KindsType,
					toolbar: '#toolbardom',
					id: 'LAY-user-role',
					cols: [tabletype]
				})

			})

		});
	</script>

}
